<?php

class Default_IndexController extends Zend_Controller_Action
{
    const BAT = 1;
    const TAT = 0;
    
    const TINTUC = 1;
    const BRAND = 9;
    const SLIDE  = 8;
    
    
    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {       
        $mdProd = new Application_Model_DbTable_Product();
        
         //danh sách sản phẩm mới
        $newprods = $mdProd->fetchAll(
            $mdProd->select()->where("isNew=?",1)
                             ->order("update DESC")
                             ->order("id ASC")
                             ->limit(3)
        );
        $this->view->news = $newprods;
        
        //danh sách sản phẩm Hot
        $hotprods = $mdProd->fetchAll(
            $mdProd->select()->where("isHot=?",1)
                             ->order("update DESC")
                             ->order("id ASC")
                             ->limit(3)
        );
        
        $this->view->hots = $hotprods;
        
        //danh sách sản phẩm bargain
        $bargainprods =  $hotprods = $mdProd->fetchAll($mdProd->select()->where("isBargain=?",1));
        $this->view->bargains = $bargainprods;
    }
    
    public function slideShowAction()
    {
        $mdArt = new Application_Model_DbTable_Article();
        $select = $mdArt->select();
        
        $data = $mdArt->fetchAll(
            $select->where("categories_id=?",self::SLIDE)
                   ->where("article_status=?",self::BAT)
                   ->order("article_local ASC")
                   ->order("idarticles DESC")
                   ->limit(4)
        );
        $this->view->rows = $data;
    }
    
    // Show danh sách 4 tin tức mới nhất
    public function newsListAction()
    {
        $mdArt = new Application_Model_DbTable_Article();
        $select = $mdArt->select();
        
        // Lấy ra 4 tin mới nhất
        $data = $mdArt->fetchAll(
            $select->where("categories_id=?",self::TINTUC)
                   ->where("article_status=?",self::BAT)
                   ->order("article_date DESC")
                   ->limit(4)
        );
        $this->view->rows = $data;
    }
    
    public function doiTacAction()
    {
        $mdArt = new Application_Model_DbTable_Article();
        $select = $mdArt->select();
        
        // Lấy danh sách các đối tác
        $data = $mdArt->fetchAll(
            $select->where("categories_id=?",self::BRAND)
                   ->where("article_status=?",self::BAT)
                   ->order("article_date DESC")
                   ->limit(4)
        );
        $this->view->rows = $data;
    }
    
    public function newsDetailAction()
    {
        $idarticle = intval($this->_request->getParam("idarticle"));
        $mdArt = new Application_Model_DbTable_Article();
        $news = $mdArt->find($idarticle)->current();
        $news_release = $mdArt->fetchAll(
            $mdArt->select()->where("idarticle!=?",$news->idarticles)
                            ->where("categories_id=?",self::TINTUC)
                            ->order("article_date DESC")
                            ->limit(8)
        );
        
        $this->c_news = $news;
        $this->r_news = $news_release;
    }
    
    public function listCategoryAction()
    {
        $mdProdCat = new Application_Model_DbTable_ProductCategory();
        $select = $mdProdCat->select();
        $select->where("status=?",1)
               ->order("local");
        $datas = $mdProdCat->fetchAll($select);
        $this->view->datas = $datas;        
    }
    
    public function listBrandAction()
    {
        $mdProdCat = new Application_Model_DbTable_Article();
        $select = $mdProdCat->select();
        $select->where("article_status=?",1)
               ->where("categories_id=?",self::BRAND)
               ->order("article_local");
        $datas = $mdProdCat->fetchAll($select);
        $this->view->datas = $datas;        
    }
    
    public function droplistAction()
    {
        $mdProdCat = new Application_Model_DbTable_ProductCategory();
        $select = $mdProdCat->select();
        $select->where("status=?",1)
               ->order("local");
        $datas = $mdProdCat->fetchAll($select);
        $this->view->datas = $datas;  
    }
    public function contactAction(){
        
        
    }

}

